package com.leetcode.Offer;

public class JZ15 {
    public int hammingWeight(int n) {

        int a = 1;
        int count = 0;
        for (int i = 0; i < 32; i++) {
            if ((n & a) != 0) {
                count++;
            }
            a = a << 1;
        }
        return count;
    }

    public int hammingWeight2(int n) {
        return Integer.bitCount(n);
    }

    public int hammingWeight3(int n) {

        int a = 1;
        int count = 0;
        for (int i = 0; i < 32; i++) {
            if ((n & a) != 0) {
                count++;
            }
            a = a << 1;
        }
        return count;
    }

    public static void main(String[] args) {
        System.out.println(new JZ15().hammingWeight(9));
        System.out.println(new JZ15().hammingWeight3(00000000000000000000000000001011));
        //System.out.println(String.valueOf(00000000000000000000000000001011));
    }

}
